
<!DOCTYPE html>
<html lang="en">
  <head>
   	<meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="/static/favicon.ico">
    <title>Mobile Security Framework</title>
    <!-- Bootstrap core CSS -->
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="/static/css/cover.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="/static/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="/static/js/ie-emulation-modes-warning.js"></script>
 <script src="/static/js/jquery.min.js"></script>
    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

    <div class="site-wrapper">

      <div class="site-wrapper-inner">

        <div class="cover-container">

          <div class="masthead clearfix">
            <div class="inner">
              <h3 class="masthead-brand"><img src="/static/img/logo-head.png" >Mobile Security Framework</h3>
              <ul class="nav masthead-nav">
                
                <li><a href="RecentScans">Recent Scans</a></li>
                <li><a href="about">About</a></li>
                <li>
                <form action="/Search" method="GET">
               <input name="md5" type="text" class="form-control" placeholder="Search MD5">
               </form></li>
              
              </ul>

			 
     
            </div>
          </div>


<style>


progress {
  width: 400px;

  margin: 25px auto;
  display: block;
  -webkit-appearance: none;

   border: 0;
    height: 18px;
    border-radius: 9px;
}

progress::-webkit-progress-bar {
  background: black;
  border-radius: 50px;
  padding: 2px;
  box-shadow: 0 1px 0px 0 rgba(255, 255, 255, 0.2);
}

progress::-webkit-progress-value {
  border-radius: 50px;
  box-shadow: inset 0 1px 1px 0 rgba(255, 255, 255, 0.4);
  background:
    -webkit-linear-gradient(45deg, transparent, transparent 33%, rgba(0, 0, 0, 0.1) 33%, rgba(0, 0, 0, 0.1) 66%, transparent 66%),
    -webkit-linear-gradient(top, rgba(255, 255, 255, 0.25), rgba(0, 0, 0, 0.2)),
    -webkit-linear-gradient(left, #66ccff, #3399ff);

  background-size: 25px 14px, 100% 100%, 100% 100%;
  -webkit-animation: move 5s linear 0 infinite;
}

@-webkit-keyframes move {
  0% {background-position: 0px 0px, 0 0, 0 0}
  100% {background-position: -100px 0px, 0 0, 0 0}
}


</style>
<div class="inner cover">
 <form id="upload_form" enctype="multipart/form-data" method="post">
  {% csrf_token %}
  <div class="fileUpload btn btn-default btn-lg" id="but">
  <input type="file" name="file" id="uploadFile" placeholder="Choose File">
  <span class="glyphicon glyphicon-cloud-upload"></span>
   Upload &amp; Analyze
  </div></br>
  <progress id="progressBar" value="0" max="100" style="width:300px;visibility:hidden;" ></progress>

  <h4 id="status"></h4>
</form>
</div>


          <div class="mastfoot">
            <div class="inner">
             <p>&copy; Mobile Security Framework {% now "Y" %} . All Rights Reserved</p>
            </div>
          </div>
        </div>
      </div>
    </div>

    <script>
function _(el){
  return document.getElementById(el);
}


$(document).ready(function () 
{
$('input[type=file]').change(function () 
{
  var val = $(this).val().toLowerCase();
  var regex = new RegExp("(.*?)\.(ipa|apk|zip)$");
  val = val.replace(/^.*[\\\/]/, '');
   try {
        if (!(regex.test(val))) 
          {
            $(this).val('');
            _('status').innerHTML = "Please upload APK/IPA/ZIP only!";
          }
          else 
          {
                _('status').innerHTML = "";
                if (_("uploadFile").files.length === 0) 
                {
                  return;
                }
                _("uploadFile").style.display= "none";
                 _("but").style.display = "none";
                var file = _("uploadFile").files[0];
                _("progressBar").style.visibility = "visible";
               
                
                var formdata = new FormData();
                formdata.append("file", file);
                var ajax = new XMLHttpRequest();
              
                ajax.upload.addEventListener("progress", progressHandler, false);
                ajax.addEventListener("load", completeHandler, false);
                ajax.addEventListener("error", errorHandler, false);
                ajax.addEventListener("abort", abortHandler, false);
                ajax.open("POST", "../Upload/");
                ajax.setRequestHeader("X-CSRFToken", '{{ csrf_token }}');
                ajax.send(formdata);
          }

      }
      catch (e) 
      {
          alert("Error:" + e);
      }
  });
});
function progressHandler(event){
  var percent = (event.loaded / event.total) * 100;
  console.log("Uploaded..."+Math.round(percent));
  _("progressBar").value = Math.round(percent);
  _("status").innerHTML = Math.round(percent)+"% Uploaded...";
}
function completeHandler(event)
{
  
  var json= JSON.parse(event.target.responseText);
  if (json.status==='error')
  {
    _("status").innerHTML = json.description;
  }
  else if (json.status==='success')
  {

    i=1;
    setInterval(function () {
      dot='';
      for (x=1;x<=i;x++)
       {
        dot+='.';
       }
       _("status").innerHTML = "Analyzing" +dot;
       i+=1;
       if(i==5)
       {
        i=1;
       }
    }, 2000);
   
    window.location.href=window.location.href+json.url;
    _("progressBar").value = 100;
  }
}
function errorHandler(event){
  _("status").innerHTML = "Upload Failed!";
}
function abortHandler(event){
  _("status").innerHTML = "Upload Aborted!";
}
</script>
    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
   
    <script src="/static/js/bootstrap.min.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="/static/js/ie10-viewport-bug-workaround.js"></script>
  </body>
</html>
